home *** CD-ROM | disk | FTP | other *** search
- Path: news.uiowa.edu!ozone!maclenna
- From: maclenna@ozone.uiowa.edu (Mark MacLennan)
- Newsgroups: comp.lang.c++
- Subject: Re: Coding Standards
- Date: 6 Mar 1996 08:08:12 GMT
- Organization: University of Iowa, Iowa City, IA, USA
- Distribution: world
- Message-ID: <4hjh5c$elk@flood.weeg.uiowa.edu>
- References: <4hj8ek$elu@sam.inforamp.net>
- Reply-To: maclenna@cgrer.uiowa.edu (Mark MacLennan)
- NNTP-Posting-Host: ozone.cgrer.uiowa.edu
-
- In article <4hj8ek$elu@sam.inforamp.net>
- rmorin@inforamp.net (Randy Charles Morin) writes:
- >The company I just started a contract with gave me a set of C++ coding
- >standards. I started reading and couldn't stop laughing. I can't reproduce
- >them word-for-word, because that wouldn't be nice to the authors and might be
- >considered a copyright violation or privacy violation, but I'll outline some
- >of the points.
-
- Some of their coding standards requirements you list are actually
- quite good, some are more dubious. Most coding standards are intended
- as guidelines to be followed unless common sense dicticates otherwise
- (and these deviations are documented accordingly). You should probably
- discuss this with the company, inquire as to the intent of some of
- the standards, rather than laugh behind their back.
-
- Some of the items you list reveal your own unfamiliarity with C++,
- which is perhaps one reason they have defined a set of C++ coding
- standards. (Hopefully the company isn't paying you based on spelling ...)
-
- - MARK
-
- >
- > -source files should have the extension .cc (not .cpp or .c).
- > -header files should have the extension .hh (not .hpp or .h).
- > -inline C++ functions should be in a file with the extension .icc
- > (not in the primary header).
-
- The latter is a little unusual but no big deal. They can always
- edit things how they like later.
-
- > -do not use the /* */ comment, except when commenting out entire
- >sections of code. My understanding is that /* */ comments are ANSI comments,
- >while // comments are not ANSI.
-
- Your understanding is wrong. Both forms are acceptable.
-
- > -a class which can be instantiated with a "new" must have a copy
- >constructor, a destructor and an assignment operator definition. This will
- >extend the project another month.
-
- Huh? It isn't that hard to do - maybe the company is planning ahead
- and anticipating the re-use of these classes by other programmers.
-
- > -never use #define instead or const. What if your concerned about the
- >mix between code space and data space.
-
- Not bad advice. Pre-processor directives should be avoided if possible.
- Better error checking too.
-
- > -variable are to be declared with the smallest possible scope.
- > void c::f()
- > {
- > {
- > int b;
- > {
- > int a;
- > a=b+c;
- > b=a+d;
- > }
- > e=b+d;
- > }
- > f=e+4;
- > }
- > this type of optimization could take forever.
-
- Use common sense when applying rules such as this. In it's strictest
- form it may not be appropriate. It is a good idea to keep variables
- local to where they are actually used.
-
- > -don't use explicit type conversions. In other words, don't program
- >in windows. Explicit type conversion is necessary to convert GDI object
- >handles.
- > -don't use implicit type conversions implicitly, use them explicitly.
- > Hello!
-
- These standards are a little odd but that may be how you worded them.
- Avoiding implicit type conversions is not such a back idea (use casts
- to explicitedly show the conversion).
-
- > -every case statement must be terminated with a break statement. What
- >if you want to step through more then one case statement?
-
- Simply document the exception to the rule ...
-
- > case ENGINE_NOT_ACTIVE:
- > start_engine();
- > case ENGINE_ACTIVE_NOT_IN_DRIVE:
- > shift_to_drive();
- > case ENGINE_ACTIVE_IN DRIVE:
- > press_accelerator();
- > break;
-
- > -don't use conditional compilation preprocessor directives. There
- >goes cross-platform development.
-
- Huh? Since these are pre-processor commands, simply run your code
- through the pre-processor for the particular platform your client wants
- the software for. What's the big deal from your point-of-view? Out-of-
- curiousity, I would inquire as to why they have this programming standard.
-
- > -optimize code only when you have a problem. So we can't optimize
- >size in order to anticipate that code size will be a problem. First we have
- >to experience the problem (most likely in the field).
-
- Perhaps they want well-written code that they and other
- future programmers can read rather than tricky "optimized" code.
- The code can always be tweaked for specific hardware at a later
- time. There is no reason that you can't write efficient code using
- appropriate algorithms and data structures.
-
- > -access functions are to be inline. Inline access functions defeat
- >the purpose of having access functions.
-
- This isn't clear. Having access functions inplemented inline isn't
- such a bad idea.
-
- > -give protected accessors for all data members. What if we need to
- >make the accessor public. Should we define one protected and one public.
-
- Accessor functions aren't "data members". Keeping your data isolated
- to a particular class and only accessible through accessor functions
- is a good idea.
-
- > -++ and -- operations should be on a separate line.
- > for (i=0; i<0;
- > i++
- > );
- > Is that better?
-
- Since the ";" is a statement separator and essentially equivalent to
- their intent of "separate lines" you needn't do the above. You seem
- to miss the point of this standard - they want to avoid problems with
- side effects.
-
- > -don't allocate memory and expected someone else will delete it later.
- >Can't use OWL, because control classes are automatically deleted for you.
-
- This is very good advice - obviously it doesn't apply for packages such
- as OWL which do it for you.
-
-